/*
 * ViewerWorker.h
 *
 *  Created on: May 24, 2011
 *      Author: madboyka
 */

#ifndef VIEWERWORKER_H_
#define VIEWERWORKER_H_
#include <QThread>
#include <QVector>
#include "Server.h"
#include "ViewerProtocol.h"

class Server;
/*!
 * Worker thread that serves the assigned viewer.
 */
class ViewerWorker : public QThread {
public:
	ViewerWorker(Server*,ViewerProtocol*);
	virtual ~ViewerWorker();
	/*!
	 * Main thread loop. Do no call.
	 */
	void run();
	/*!
	 * Check for new objects in the pool and sends them to the assigned viewer.
	 */
	void sendNewObjects();
	/*!
	 * Checks for deleted objects and sends the indexes to the assigned viewer.
	 */
	void sendDeletedObjects();
	/*!
	 * Sends the modified object location matrices to the viewer.
	 */
	void sendNewLocations();
	/*!
	 * Adds a new ElementData to the new objects pool, to be scheduled for sending.
	 */
	void addNewElement(ElementData);
	/*!
	 * Adds a deleted object index to the pool, to be scheduled for sending.
	 */
	void addDeletedElement(int);
private:
	bool running;
	Server* server;
	ViewerProtocol *protocol;
	QVector<int> deletedElements;
	QVector<ElementData> newElements;

};

#endif /* VIEWERWORKER_H_ */
